package com.nine.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class AopAspect {

    @Pointcut("execution(* com.nine.controller.AopController.test(..))")
    public void testAop() {
        log.info("AopAspect test...........................");
    }

    @Before("testAop()")
    public void before() {
        log.info("before...................................");
    }

    @After("testAop()")
    public void after() {
        log.info("after...................................");
    }

    @AfterReturning("testAop()")
    public void afterReturning() {
        log.info("afterReturning...................................");
    }

    @AfterThrowing("testAop()")
    public void afterThrowing() {
        log.info("afterThrowing...................................");
    }

    @Around("testAop()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        Object result = null;
        try {
            log.info(">>>>>>>>>>around---before........................................");
            result = joinPoint.proceed();
            log.info(">>>>>>>>>>around---afterReturning ...................................");
        }
        catch (Throwable e) {
            log.info(">>>>>>>>>>around---throwing........................................");
            throw e;
        }
        finally {
            log.info(">>>>>>>>>>around---after...................................");
        }
        return result;
    }

}
